/*
 * PKL 51 - Subseksi Data Entry
 */

/*
 * PanelLogin.java
 *
 * Created on Jan 6, 2012, 9:08:51 PM
 */

package pkl51.view;

import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import pkl51.component.ButtonGloss;
import pkl51.controller.LoginController;
import pkl51.model.MahasiswaModel;
import pkl51.model.event.MahasiswaListener;

/**
 *
 * @author ASUS
 */
public class PanelLogin extends javax.swing.JPanel implements MahasiswaListener{

    private LoginController controller;
    private MahasiswaModel model;
    /** Creates new form PanelLogin */
    public PanelLogin() {
        model = MahasiswaModel.getInstance();
        model.setListener(this);
        controller = new LoginController();
        controller.setModel(model);
        
        initComponents();
        textFieldNewPassword.setVisible(false);
        textFieldConfirmPassword.setVisible(false);
        labelNewPassword.setVisible(false);
        labelConfirmPassword.setVisible(false);
        buttonChange.setVisible(false);
        buttonCancel.setVisible(false);
    }

    public JPasswordField getTextFieldConfirmPassword() {
        return textFieldConfirmPassword;
    }

    public JPasswordField getTextFieldNewPassword() {
        return textFieldNewPassword;
    }

    public JPasswordField getTextFieldPassword() {
        return textFieldPassword;
    }

    public JTextField getTextFieldUsername() {
        return textFieldUsername;
    }

    public ButtonGloss getButtonChange() {
        return buttonChange;
    }

    public ButtonGloss getButtonCancel() {
        return buttonCancel;
    }

    public ButtonGloss getButtonLogin() {
        return buttonLogin;
    }

    public JLabel getLabelConfirmPassword() {
        return labelConfirmPassword;
    }

    public JLabel getLabelNewPassword() {
        return labelNewPassword;
    }

    public ButtonGloss getButtonExit() {
        return buttonExit;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelGradient1 = new pkl51.component.PanelGradient();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        labelNewPassword = new javax.swing.JLabel();
        labelConfirmPassword = new javax.swing.JLabel();
        textFieldPassword = new pkl51.component.PasswordField();
        textFieldNewPassword = new pkl51.component.PasswordField();
        textFieldConfirmPassword = new pkl51.component.PasswordField();
        textFieldUsername = new pkl51.component.UserNameField();
        buttonCancel = new pkl51.component.ButtonGloss();
        buttonChange = new pkl51.component.ButtonGloss();
        buttonExit = new pkl51.component.ButtonGloss();
        buttonLogin = new pkl51.component.ButtonGloss();
        panelGambar1 = new pkl51.component.PanelGambar();
        jLabel3 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        setOpaque(false);
        setLayout(new java.awt.BorderLayout());

        panelGradient1.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Username");

        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Password");

        labelNewPassword.setForeground(new java.awt.Color(255, 255, 255));
        labelNewPassword.setText("New Password");

        labelConfirmPassword.setForeground(new java.awt.Color(255, 255, 255));
        labelConfirmPassword.setText("Confirm Password");

        textFieldPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldPasswordActionPerformed(evt);
            }
        });

        textFieldNewPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldNewPasswordActionPerformed(evt);
            }
        });

        textFieldConfirmPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldConfirmPasswordActionPerformed(evt);
            }
        });

        textFieldUsername.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldUsernameActionPerformed(evt);
            }
        });

        buttonCancel.setText("Cancel");
        buttonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelActionPerformed(evt);
            }
        });

        buttonChange.setText("Change");
        buttonChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonChangeActionPerformed(evt);
            }
        });

        buttonExit.setText("Exit");
        buttonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExitActionPerformed(evt);
            }
        });

        buttonLogin.setText("Login");
        buttonLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLoginActionPerformed(evt);
            }
        });

        panelGambar1.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));

        javax.swing.GroupLayout panelGambar1Layout = new javax.swing.GroupLayout(panelGambar1);
        panelGambar1.setLayout(panelGambar1Layout);
        panelGambar1Layout.setHorizontalGroup(
            panelGambar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 116, Short.MAX_VALUE)
        );
        panelGambar1Layout.setVerticalGroup(
            panelGambar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 115, Short.MAX_VALUE)
        );

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        jLabel3.setText("PLEASE LOGIN");

        javax.swing.GroupLayout panelGradient1Layout = new javax.swing.GroupLayout(panelGradient1);
        panelGradient1.setLayout(panelGradient1Layout);
        panelGradient1Layout.setHorizontalGroup(
            panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGradient1Layout.createSequentialGroup()
                .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelGradient1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelGambar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panelGradient1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(labelConfirmPassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(panelGradient1Layout.createSequentialGroup()
                                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(23, 23, 23))
                                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelNewPassword))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(textFieldPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                                    .addComponent(textFieldNewPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                                    .addComponent(textFieldConfirmPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                                    .addComponent(textFieldUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
                            .addGroup(panelGradient1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(buttonChange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(buttonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(buttonLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(panelGradient1Layout.createSequentialGroup()
                        .addGap(106, 106, 106)
                        .addComponent(jLabel3)))
                .addContainerGap())
        );
        panelGradient1Layout.setVerticalGroup(
            panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGradient1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelGambar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelGradient1Layout.createSequentialGroup()
                        .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(textFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(textFieldPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelNewPassword)
                            .addComponent(textFieldNewPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelConfirmPassword)
                            .addComponent(textFieldConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelGradient1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(buttonChange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(buttonExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(buttonLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(panelGradient1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

private void textFieldUsernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldUsernameActionPerformed
    textFieldPassword.requestFocusInWindow();
}//GEN-LAST:event_textFieldUsernameActionPerformed

private void textFieldPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldPasswordActionPerformed
    buttonLogin.requestFocusInWindow();
    controller.login(this);
}//GEN-LAST:event_textFieldPasswordActionPerformed

private void textFieldNewPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldNewPasswordActionPerformed
    textFieldConfirmPassword.requestFocusInWindow();
}//GEN-LAST:event_textFieldNewPasswordActionPerformed

private void textFieldConfirmPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldConfirmPasswordActionPerformed
    buttonChange.requestFocusInWindow();
    controller.changePassword(this);
}//GEN-LAST:event_textFieldConfirmPasswordActionPerformed

private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed
    controller.cancelChangePassword(this);
}//GEN-LAST:event_buttonCancelActionPerformed

private void buttonChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonChangeActionPerformed
    controller.changePassword(this);
}//GEN-LAST:event_buttonChangeActionPerformed

private void buttonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExitActionPerformed
    
    //jika mau pake server mysql portabel, uncomment code di bawah ini
//    Thread threadShutdown = new Thread(new ShudownServer());
//    threadShutdown.start();
    
    System.exit(0);
}//GEN-LAST:event_buttonExitActionPerformed

private void buttonLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLoginActionPerformed
    controller.login(this);
    textFieldNewPassword.requestFocusInWindow();
}//GEN-LAST:event_buttonLoginActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private pkl51.component.ButtonGloss buttonCancel;
    private pkl51.component.ButtonGloss buttonChange;
    private pkl51.component.ButtonGloss buttonExit;
    private pkl51.component.ButtonGloss buttonLogin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel labelConfirmPassword;
    private javax.swing.JLabel labelNewPassword;
    private pkl51.component.PanelGambar panelGambar1;
    private pkl51.component.PanelGradient panelGradient1;
    private pkl51.component.PasswordField textFieldConfirmPassword;
    private pkl51.component.PasswordField textFieldNewPassword;
    private pkl51.component.PasswordField textFieldPassword;
    private pkl51.component.UserNameField textFieldUsername;
    // End of variables declaration//GEN-END:variables

    @Override
    public void onChange(MahasiswaModel model) {
        textFieldUsername.setText(model.getNim());
        textFieldPassword.setText(model.getPassword());
    }

}
